﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using HZ.Supervise.Model.Enum;

namespace HZ.Supervise.Web.Secondphase.Stocks
{
    public partial class Stocks_Sum : BasePage
    {
        IBLL.IBLL_Stocks ibs = BLLFactory.IBLL_Stocks();

        public Stocks_Sum()
        {
            this.ModuleNo = Module.库存统计.ToString();
            this.PageOperateType = OperateType.库存统计.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                dataBind();
            }
        }

        private void dataBind()
        {
            int i = 0;

            StringBuilder sqlwhere = new StringBuilder();

            if (!string.IsNullOrEmpty(txtProductName.Text.Trim()))
            {
                sqlwhere.Append(" and ProductName like '%" + HZ.Supervise.DAL.DAL_Helper.Replace(txtProductName.Text.Trim()) + "%'");
            }
            if (!string.IsNullOrEmpty(txtOutlookc.Text.Trim()))
            {
                sqlwhere.Append(" and Outlookc like '%" + HZ.Supervise.DAL.DAL_Helper.Replace(txtOutlookc.Text.Trim()) + "%'");
            }
            if (!string.IsNullOrEmpty(txtPinYinCode.Text.Trim()))
            {
                sqlwhere.Append(" and GoodsID like '%" + HZ.Supervise.DAL.DAL_Helper.Replace(txtPinYinCode.Text.Trim()) + "%'");
            }
            if (!string.IsNullOrEmpty(txtUnit.Text.Trim()))
            {
                sqlwhere.Append(" and Unit like '%" + HZ.Supervise.DAL.DAL_Helper.Replace(txtUnit.Text.Trim()) + "%'");
            }
            if (!string.IsNullOrEmpty(txtMedicineModel.Text.Trim()))
            {
                sqlwhere.Append(" and Unit like '%" + HZ.Supervise.DAL.DAL_Helper.Replace(txtUnit.Text.Trim()) + "%'");
            } if (!string.IsNullOrEmpty(txtPack.Text.Trim()))
            {
                sqlwhere.Append(" and Pack = '" + HZ.Supervise.DAL.DAL_Helper.Replace(txtUnit.Text.Trim()) + "'");
            }
            sqlwhere.Append(" order by ProductName");
            gvwInfo.AutoGenerateColumns = false;
            gvwInfo.DataSource = ibs.GetHosComTotalStock(sqlwhere.ToString(), AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out i);
            AspNetPager1.RecordCount = i;
            gvwInfo.DataBind();

        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            dataBind();
        }
    }
}
